<?php

/*
 * 帖子类型管理
 */
session_start();
include_once dirname(__FILE__)."/../src/daos/topictypesdao.php";
include_once dirname(__FILE__)."/../src/daos/topicsdao.php";
include_once dirname(__FILE__)."/../conf/smarty.conf.php";

// 权限验证

//
if(isset($_POST["topictype_name"])){ // 添加分类
	$topictype_name = strval($_POST["topictype_name"]);
	$topictype_description = "";
	if(isset($_POST["topictype_description"])){
		$topictype_desctiption = strval($_POST["topictype_description"]);
	}
		
	$topictype = new TopicType();
	$topictype->setTopicTypeName($topictype_name);
	$topictype->setTopicTypeDescription($topictype_description);
	$topictypesdao = new TopicTypesDAO();
	$topictypesdao->insertTopicType($topictype);
}
if(isset($_REQUEST["topictype_id"])){ // 删除分类
	$topictype_id = intval($_REQUEST["topictype_id"]);
	$topictypesdao = new TopicTypesDAO();
	$topicsdao = new TopicsDAO();
	// 将该分类下的文章改为“未分类”
	$topicsdao->reType($topictype_id,  -1);
	// 删除这个分类
	$topictypesdao->deleteTopicType($topictype_id);
	
}
$topictypesdao = new TopicTypesDAO();
$topictypes = $topictypesdao->getAllTopicTypes();	// 取出所有帖子分类
$title = "后台管理";
$smarty->assign("title",$title);
$smarty->assign("topictypes", $topictypes );
$smarty->display("frm_topictypes_mng.html");
?>
